package com.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.entity.DischargeSummaryMedicine;
import com.demo.mapper.DischargeSummaryMedicineMapper;
import com.demo.service.IDischargeSummaryMedicineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 出院带药清单表 服务实现类
 * @author zm
 * @since 2020-12
 */
@Service
@Slf4j
public class DischargeSummaryMedicineServiceImpl extends ServiceImpl<DischargeSummaryMedicineMapper, DischargeSummaryMedicine> implements IDischargeSummaryMedicineService {
    @Resource
    DischargeSummaryMedicineMapper dischargeSummaryMedicineMapper;

    /**
     * 批量新增出院药物
     * @param list        药物集合
     * @param summaryId   出院总结ID
     * @return
     */
    @Override
    public boolean addMedicineSummary(List<DischargeSummaryMedicine> list,Integer summaryId) {
        log.info("集合信息："+list);
        if (list.size() != 0) {
            for (DischargeSummaryMedicine medicine : list) {
                medicine.setDischargeSummaryId(summaryId);
                boolean flag = this.save(medicine);
                if (flag == false) return false;
            }
        }
        return true;
    }

    /**
     * 删除出院带药【通过出院单ID】
     * @param summaryId   出院总结ID
     * @return
     */
    @Override
    public boolean deleteMedicineSummary(Integer summaryId) {
        QueryWrapper<DischargeSummaryMedicine> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("discharge_summary_id",summaryId);
        int flag = dischargeSummaryMedicineMapper.delete(queryWrapper);
        if (flag == 0)return false;
        return true;
    }
}
